package com.endava.Parsing;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/*
 * 1. Extract phone numbers from a text :
 a) 07xx-xxx xxx
 b) 07xx-xxxxxx
 c) 07xx.xxx xxx
 d) 07xx.xxxxxx
 e) (07xx) xxx xxx
 f) all

 */
/**
 * The program is implementing a basic phone formatter
 * 
 * @author adumitrescu
 * 
 */
public class Regex {
	/** The class that holds numberFormat method */
	private String regex;
	private String input;

	
	public Regex(String regex, String input) {		
				
		this.regex = regex;
		this.input = input;
	}
	
	/** The getter for regex variable */
	public String getRegex() {
		return regex;
	}

	/** The setter for the regex variable */
	public void setRegex(String regex) {
		this.regex = regex;
	}

	/** The getter for input variable */
	public String getInput() {
		return input;
	}

	/** The setter for the input variable */
	public void setInput(String input) {
		this.input = input;
	}

	/**
	 * The method that takes 2 parameters of type string
	 * 
	 * @param String
	 *            that passes the value of the regular expression.
	 * @param String
	 *            that passes the actual input that will be parsed.
	 * */
	public String numberFormat() {
		Pattern p = Pattern.compile(regex);
		Matcher m = p.matcher(input);
		/** passes to trough the input string */
		while (m.find()) {// if it find's a value then the expression = true and
							// goes on, if not it goes out of the loop
			System.out.println(" " + m.group());// prints the index of the
												// matching regular expression
												// and the value of it
		}
		return input;// returns the new input after parsing
	}
	
	public static void main(String[] args) {
		Regex r = new Regex(":", "ab:cd:ef");
		r.numberFormat();
	}
	
	
}
